package com.bjtu.transactionclient.controller;

import com.bjtu.transactionclient.api.api.IndexService;
import com.bjtu.transactionclient.api.vo.request.SyncEntityRequest;
import com.bjtu.transactionclient.api.vo.request.UserIndexNoQueryRequest;
import com.bjtu.transactionclient.api.vo.request.UserIndexNoQueryTypeRequest;
import com.bjtu.transactionclient.base.result.Result;
import com.bjtu.transactionclient.domain.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author caiyuli
 * @date 2020/4/23 3:34 下午
 */


@RestController
@RequestMapping("/indexNo")
@Api(description = "关于索引查询的接口")
public class IndexNoController {

    @Autowired
    private IndexService indexService;

    @RequestMapping(value = "/query-indexNo", method = RequestMethod.POST)
    @ApiOperation("提供索引号查询出 UserIndexNo， 没有该索引号就返回code = -1")
    public Result<UserIndexNoTable> queryUserIndexNoByIndex(@RequestBody @Validated UserIndexNoQueryRequest request){
        UserIndexNoTable result =  indexService.queryUserIndexNo(request.getIndexNo());
        return Result.success(result);
    }

    @RequestMapping(value = "/query-journal-CN", method = RequestMethod.POST)
    @ApiOperation("提供索引号查询出 JournalChinese， 没有数据就code = -1")
    public Result<JournalChinese> queryJournalCnByIndex(@RequestBody @Validated UserIndexNoQueryRequest request){
        JournalChinese result = indexService.queryJournalChineseByIndexNo(request.getIndexNo());
        return Result.success(result);
    }

    @RequestMapping(value = "/query-journal-EN", method = RequestMethod.POST)
    @ApiOperation("提供索引号查询出 JournalEnglish， 没有数据就code = -1")
    public Result<JournalEnglish> queryJournalEnByIndex(@RequestBody @Validated UserIndexNoQueryRequest request){
        JournalEnglish result = indexService.queryJournalEnglishByIndexNo(request.getIndexNo());
        return Result.success(result);
    }

    @RequestMapping(value = "/query-journal-paper-EN", method = RequestMethod.POST)
    @ApiOperation("提供索引号查询出 JournalPaperEnglish， 没有数据就code = -1")
    public Result<JournalPaperEnglish> queryJournalPaperCnByIndex(@RequestBody @Validated UserIndexNoQueryRequest request){
        JournalPaperEnglish result = indexService.queryJournalPaperEnglishByIndexNo(request.getIndexNo());
        return Result.success(result);
    }

    @RequestMapping(value = "/query-journal-paper-CN", method = RequestMethod.POST)
    @ApiOperation("提供索引号查询出 JournalPaperChinese， 没有数据就code = -1")
    public Result<JournalPaperChinese> queryJournalPaperEnByIndex(@RequestBody @Validated UserIndexNoQueryRequest request){
        JournalPaperChinese result = indexService.queryJournalPaperChineseByIndexNo(request.getIndexNo());
        return Result.success(result);
    }

    @RequestMapping(value = "/query", method = RequestMethod.POST)
    @ApiOperation("提供索引号查询出 UserIndexNo， 没有该索引号就返回code = -1")
    public Result query(@RequestBody @Validated UserIndexNoQueryTypeRequest request){
        Result result =  indexService.queryEntity(request);
        return result;
    }



}
